package co.id.btel.create.pdf;

import java.io.FileOutputStream;

import utilities.ChunkModif;
import utilities.Constants;
import utilities.PdfUtil;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfHeader {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			String FILE = "E:/BTE/samplePdf/Header.pdf";
			Document document = new Document();
			PdfWriter writer = PdfWriter.getInstance(document,
					new FileOutputStream(FILE));
			ChunkModif event = new ChunkModif();
			writer.setPageEvent(event);
			document.open();
			PdfUtil.addMetaData(document);
			addHeader(document);
			document.close();
			System.out.print("done!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param document
	 * @throws DocumentException
	 */
	public static void addHeader(Document document) throws DocumentException {

		PdfPTable table = new PdfPTable(1);
		table.setWidthPercentage(100);

		// colomn 1
		Paragraph p = new Paragraph();
		Chunk ch = new Chunk("INFORMASI BIAYA PENGGUNAAN |",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_A,
						Font.NORMAL, Constants.AHA_BASE));
		p.add(ch);
		ch = new Chunk(" BILLING STATEMENT", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_A, Font.ITALIC,
				Constants.AHA_BASE));
		p.add(ch);
		PdfPCell c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// new line
		p = new Paragraph();
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		document.add(table);
	}

}
